<template>
  <div>
    <!-- 仓库管理 -->
    <!-- <tamplate v-if="routernd"> -->
    <div class="warehouse-contain">
      <!-- 上--搜索部分 -->
      <div class="warehouse-search">
        <el-row>
          <el-col :span="6"><div class="grid-content bg-purple" />
            <span>仓库编号</span>
            <el-input v-model="params.like_code" placeholder="请输入" size="medium" label="" maxlength="10" type="text" />
          </el-col>
          <el-col :span="6"><div class="grid-content bg-purple" />
            <span>仓库名称</span>
            <el-input v-model="params.like_name" placeholder="请输入" size="medium" label="" />
          </el-col>
          <el-col :span="6"><div class="grid-content bg-purple-light" />
            <div class="select">
              <span>仓库状态</span>
              <el-select v-model="params.status" placeholder="请选择" size="medium">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col>
          <el-col :span="6"><div class="grid-content bg-purple-light" />
            <el-button-group>
              <el-row>
                <el-col :span="12"><el-button type="warning" round @click="searchButton">搜索</el-button></el-col>
                <el-col :span="12"><el-button @click="resetForm">重置</el-button></el-col>
              </el-row>
            </el-button-group>
          </el-col>
        </el-row>
      </div>
      <!-- 下--表格部分 -->
      <div class="warehouse-table">
        <div class="warehouse-table-button">
          <el-button type="success" round @click="toNewpage">新建仓库</el-button>
        </div>
        <el-table
          :data="tableData"
          border
          style="width: 100%"
          :header-cell-style="{
            color: '#909399',
            'text-align':'center',
            background: '#f9f6ee',
            'font-weight':'400px'
          }"
          :row-class-name="tableRowClassName"
        >
          <!-- 序号 -->
          <el-table-column
            type="index"
            label="序号"
            width="70"
            align="center"
          />
          <!-- 仓库编码 -->
          <el-table-column
            prop="code"
            label="仓库编码"
            width="120"
            align="center"
          />
          <!-- 仓库名称 -->
          <el-table-column
            prop="name"
            label="仓库名称"
            width="120"
            align="center"
          />
          <!-- 仓库类型 -->
          <el-table-column
            prop="type"
            label="仓库类型"
            width="120"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ warehouseType[scope.row.type] }}</span>
            </template>
          </el-table-column>
          <!-- 省/市/区 -->
          <el-table-column
            prop="location"
            label="省/市/区"
            width="300"
            align="center"
          />
          <!-- 详细地址 -->
          <el-table-column
            prop="address"
            label="详细地址"
            width="120"
            align="center"
          />
          <!-- 插槽配合三元，进行数字映射 -->
          <!-- 仓库状态 -->
          <el-table-column
            prop="status"
            label="仓库状态"
            width="160"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.status == 1?"启用":"停用" }}</span>
            </template>
          </el-table-column>
          <!-- 仓库面积 -->
          <el-table-column
            prop="address"
            label="仓库面积"
            width="160"
            align="center"
          />
          <!-- 仓库面积 -->
          <el-table-column
            prop="surface"
            label="仓库面积"
            width="160"
            align="center"
          />
          <!-- 负责人 -->
          <el-table-column
            prop="personName"
            label="负责人"
            width="160"
            align="center"
          />
          <!-- 联系电话 -->
          <el-table-column
            prop="phone"
            label="联系电话"
            width="160"
            align="center"
          />
          <!-- 更新时间 -->
          <el-table-column
            prop="updateTime"
            label="更新时间"
            width="160"
            align="center"
          />
          <!-- 操作 -->
          <el-table-column
            fixed="right"
            label="操作"
            width="180"
            align="center"
          >
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="handleClick(scope.row)">编辑</el-button>
              <el-button type="text" size="small">停用</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 下下--分页器 -->
        <div class="block">
          <el-pagination
            align="center"
            :current-page="params.current"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="params.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="+total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          >1</el-pagination>
        </div>
      </div>
    </div>
    <!-- </tamplate> -->
    <!-- 三级路由窗口插入在这 -->
    <!-- <template>
      <router-view name="warehouseDetails" />
    </template> -->
    <!-- </tamplate> -->
  </div>
</template>

<script>
import { pageSearch } from '@/api'
export default {
  data() {
    return {
      // 选择器选项
      options: [{
        value: null,
        label: '全部'
      }, {
        value: 0,
        label: '停用'
      }, {
        value: 1,
        label: '启用'
      }],
      // value: '',
      // table获取的数据
      tableData: [],
      // 后端传回来的数据
      params: {
        // 当前页和一页显示几条
        current: 1,
        size: 10,
        // 仓库编号  仓库名称  仓库状态
        like_code: '',
        like_name: '',
        status: ''
      // descs:createTime
      },
      // 分页器总页数
      total: 0,
      // 判断仓库类型(一对多的数字映射)
      warehouseType: {
        ZZ: '中转仓',
        JG: '加工仓',
        CB: '储备仓',
        LC: '冷藏仓'
      }
    }
  },
  // 调仓库列表的接口
  created() {
    this.getWearhouseList()
  },
  methods: {
    // 斑马表格
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 0) {
        return ''
      } else {
        return 'warning-row'
      }
    },
    // // 指定修改最后一栏的字体颜色
    // setCellColor({ row, column, rowIndex, columnIndex }) {
    //   if (columnIndex === 13) {
    //     return 'color:#ffb200;'
    //   }
    // },
    // 封装获得仓库列表
    async getWearhouseList() {
      const res = await pageSearch(this.params)
      // console.log(res)
      this.tableData = res.data.data.records
      this.total = res.data.data.total
    // console.log(this.tableData)
    },
    // 分页器
    // 每页多少条
    handleSizeChange(val) {
      this.params.size = val
      this.getWearhouseList()
      // console.log(`每页 ${val} 条`)
    },
    // 当前第几页
    handleCurrentChange(val) {
      this.params.current = val
      this.getWearhouseList()
      // console.log(`当前页: ${val}`)
    },
    // 搜索筛选表格数据
    searchButton() {
      this.getWearhouseList()
      // console.log('111')
    },
    // 表单重置
    // 把字段变为初始值，并重新调用接口，就能实现表单重置
    resetForm() {
      this.params = {
        // 当前页和一页显示几条
        current: 1,
        size: 10,
        // 仓库编号  仓库名称  仓库状态
        like_code: '',
        like_name: '',
        status: ''
      // descs:createTime
      }
      this.getWearhouseList()
    },
    // 点击新建仓库按钮(路径里面没有带参数)
    toNewpage() {
      this.$router.push({
        path: `/warehouseDetails/${null}`
      })
    },
    // 编辑仓库,也跳转到WarehouseDetails页面(路径里面有带参数id)
    handleClick(row) {
      // console.log(row, '编辑row')
      this.$router.push({
        name: 'warehouseDetails',
        params: {
          id: row.id
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.warehouse-contain{
  background-color: #fdfafa;
}
// 上--搜索部分css
 .warehouse-search{
  height: 127px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 6px 0 rgb(144 142 142 / 17%);
  padding: 30px;
  margin: 20px 30px;
}
.el-row{
  padding: 10px;
}
span{
  font-size: 12px;
  margin-bottom: 10px;
  color: #887e7e;
}
.el-input{
  width: 340px;
}
.el-select{
  width: 340px;
}
.el-button-group{
  margin-left:40% ;
  margin-top:15px ;
  // padding-left: 15px;
  // padding-right: 15px;
  text-align: center;
  display: flex;
  align-items: center;
}
.searchButton{
  width: 60px;
  height: 38px;
  font-size: 14px;
  background: #ffb200;
  color: #332929;
  padding: 1px 26px;
  text-align: center;
}
.el-col{
  display: flex;
  flex-direction:column;
  padding: 0 15px;
}
.select{
  display: flex;
  flex-direction:column;
  padding: 0 15px;
}
// 新建按钮css
.warehouse-table-button{
  margin-left: 30px;
  margin-top: 20px;
  margin-bottom: 20px;
  padding-top: 20px;
  .el-button{
  background: #00be76;
  color: #fff;
}
}

// 下--table部分css
.warehouse-table{
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 6px 0 rgb(144 142 142 / 17%);
  margin: 20px 30px;
  padding-bottom: 10px;
}
.el-table{
  margin-bottom: 20px;
}
 ::v-deep tbody tr:hover>td,
 ::v-deep tbody tr.hover-row>td { background-color:#fff6e3 }
// 表格斑马自定义颜色
::v-deep .el-table__row.warning-row {
  background: #fdfcf9;
}
// 分页器样式
.block{
  margin-bottom: 20px;
}
</style>

